﻿using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using HiauPdm.Bll;
using HiauPdm.Web;

namespace HiauPdm.Web
{
    public partial class WzXzLeft : PageBase
    {
        protected override bool IsAccess()
        {
            return true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LblTitle.Text = "物资类别";
                TreeNode tn = new TreeNode("物资类别", "0");
                tn.SelectAction = TreeNodeSelectAction.None;
                tn.PopulateOnDemand = true;
                TreeWzlb.Nodes.Add(tn);
                TreeWzlb.ExpandDepth = 1;
            }
        }

        protected void TreeWzlb_TreeNodePopulate(object sender, TreeNodeEventArgs e)
        {
            DataSet dsWzlb = null;
            if (int.Parse(e.Node.Value) == 0 && e.Node.Depth == 0)
            {
                DataSet ds1 = BWgjCx.GetChildWgjlb(int.Parse(e.Node.Value));
                DataSet ds2 = BJcSj.GetChildWzLs(int.Parse(e.Node.Value));
                if (ds1 != null && ds2 != null)
                {
                    dsWzlb = ds1;
                    dsWzlb.Tables[0].Merge(ds2.Tables[0]);
                    DataRow dr = dsWzlb.Tables[0].NewRow();
                    dr["ID"] = 0;
                    dr["编号"] = "H";
                    dr["类别名称"] = "设计件";
                    dr["含子类别"] = true;
                    dsWzlb.Tables[0].Rows.Add(dr);
                }
            }
            else if (e.Node.Text.Substring(1, 1) == "1" || e.Node.Text.Substring(1, 1) == "2")
            {
                dsWzlb = BWgjCx.GetChildWgjlb(int.Parse(e.Node.Value));
            }
            else if (e.Node.Text.Substring(1, 1) == "3")
            {
                dsWzlb = BJcSj.GetChildWzLs(int.Parse(e.Node.Value));
            }
            else if (e.Node.Text.Substring(1, 1) == "H")
            {
                dsWzlb = BCpSjCx.GetChildCplb(int.Parse(e.Node.Value));
            }
            if (dsWzlb != null && dsWzlb.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsWzlb.Tables[0].Rows)
                {
                    TreeNode tn = new TreeNode(string.Format("[{0}]{1}", dr["编号"], dr["类别名称"]), dr["ID"].ToString());
                    tn.ToolTip = tn.Text;
                    if ((bool)dr["含子类别"])
                    {
                        tn.SelectAction = TreeNodeSelectAction.Expand;
                        tn.PopulateOnDemand = true;
                    }
                    else
                    {
                        tn.NavigateUrl = "javascript:GotoUrl('" + dr["编号"].ToString() + "');";
                    }
                    e.Node.ChildNodes.Add(tn);
                }
            }
        }
    }
}